<style type="text/css">
    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }

</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="驾驶证编号" prop="licenseid">
            <i-input v-model="formValidate.licenseid" placeholder="请输入驾驶证编号"></i-input>
        </Form-item>
        <Form-item label="车辆类型" prop="alloweddrive">
            <i-select v-model="formValidate.alloweddrive" placeholder="请选择车辆类型">
                <template v-for="(item,index) in carTypeArr">
                    <i-option :value="item">{{item}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="上次驾驶审核">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" :value="formValidate.lastcheckdate" placeholder="选择上次驾驶审核日期" @on-change="changeUpDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="获取驾驶证">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" :value="formValidate.firstcheckdate" placeholder="选择获取驾驶证日期" @on-change="changeGetDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="下次驾照审核">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" :value="formValidate.nextcheckdate" placeholder="选择下次驾照审核日期" @on-change="changeNextDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <!--上传图片-->
        <upImage :upImageData="upImageData" v-if="upImageData.img" @get-postImg-data="getImgData" ></upImage>
        <upImage :upImageData="upImageData2" v-if="upImageData2.img" @get-postImg-data="getImgData2"></upImage>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="jumpPage('','DriverList')"  style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import upImage from '../../components/upImage';

    /**
     * 人员Id peopleid, 驾驶证正本照片路径 licenseimage,
     * 驾驶证副本照片路径 licenseimageb,
     * 上一次驾驶审查日期 lastcheckdate,
     * 获取驾驶证时间 firstcheckdate
     * 下一次驾照审查时间 nextcheckdate，
     * 驾驶证编号 licenseid，准驾车型 alloweddrive
     */

    export default {
        data() {
            return {
                carTypeArr: [
                    '大型汽车', '小型汽车', '专用汽车', '特种车', '电瓶车', '三轮摩托车', '二轮摩托车', '四轮农用运输车', '三轮农用运输车',
                ],
                formValidate: {
                    //添加字段
                    licenseid: '',
                    alloweddrive: '',
                    lastcheckdate: '',
                    firstcheckdate: '',
                    nextcheckdate: '',
                },
                ruleValidate: {},
                //被人员列表
                principalId: '',
                principalArr: [],
                personalName: '请选择',
                selectPeopelIsShow: false,
                //图片
                imageLicenseimage: [],
                upImageData: {
                    title: '驾驶证正面',
                    img:'',
                    edit:1,
                },
                imageLicenseimageb: [],
                upImageData2: {
                    title: '驾驶证反面',
                    img:'',
                    edit:1,
                },
            }
        },
        created: function () {
                let id = this.$route.query.id;

                if (id && id.length > 0) {
                    this.getDetail(id)
                }

        },
        components: {
            upImage
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            getImgData: function (value) {
                console.log('图片数据：', value);
                this.imageLicenseimage =value;
            },
            getImgData2: function (value) {
                console.log('图片数据：', value);
                this.imageLicenseimageb =value;
            },
            changeUpDate: function (date) {
                console.log('date:', date);
                this.formValidate.lastcheckdate = date;
            },
            changeGetDate: function (date) {
                console.log(date);
                this.formValidate.firstcheckdate = date;

            },
            changeNextDate: function (date) {
                console.log(date);
                this.formValidate.nextcheckdate = date;

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                console.log('this.$refs[name].model:',this.$refs[name].model);
                console.log(this.$refs[name].validate())

                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                    console.log('dddddfdsfsdfsdf')

                })
            },

            //获取车牌
            getCarCityData() {
                let that = this;

                this.carCityArr = carCity;
                if (this.selectPeopelIsShow) {
                    this.selectPeopelIsShow = false;
                } else {
                    this.selectPeopelIsShow = true;
                }
                console.log('车辆地区:', carCity)
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;
            },
            //详情
            getDetail: function (id) {
                let that = this;
                that.$Loading.start();

                let para = {
                    id: this.$route.query.id,
                };

                apiUtil.get(that, apiUtil.urls.DriverDetail, para, function (res) {
                    that.$Loading.finish();

                    that.formValidate.licenseid = res.Msg.licenseid;
                    that.formValidate.alloweddrive = res.Msg.alloweddrive;
                    that.formValidate.lastcheckdate = res.Msg.lastcheckdate;
                    that.formValidate.firstcheckdate = res.Msg.firstcheckdate;
                    that.formValidate.nextcheckdate = res.Msg.nextcheckdate;
                    that.principalId = res.Msg.peopleid;
                    that.personalName = res.Msg.PeopleName;


                    //传给子组件数据
                    that.upImageData.img ={
                        response:{
                            Msg:res.Msg.licenseimage
                        },
                        status: 'finished',
                        percentage: '100',
                        showProgress: false
                    };
                    //获取默认详情数据
                    that.imageLicenseimage.push({
                        img:res.Msg.licenseimage
                    });
                    that.upImageData2.img ={
                        response:{
                            Msg:res.Msg.licenseimageb
                        },
                        status: 'finished',
                        percentage: '100',
                        showProgress: false
                    };
                    that.imageLicenseimageb.push({
                        img:res.Msg.licenseimageb
                    });
                    console.log('详情数据')
                    // that.imageLicenseimageb[0].img =res.Msg.licenseimageb;

                });
            },
            //修改
            updateData: function (model) {
                let that = this;

                model.id = this.$route.query.id;
                model.licenseimage =this.imageLicenseimage[0].img;
                model.licenseimageb =this.imageLicenseimageb[0].img;
                model.peopleid =this.principalId;

                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditDriver, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('编辑成功')
                });
            },


        }
    }
</script>
